/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 2 -*- */
/**
* @file TestAccelerometer.c
* 
* Library for testing the accelerometers library code.
* 
* @author Miguel Ángel Vílchez López 2008 <sacra@openmatica.es>
*
* Codigo is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* Codigo is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License along
* with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include <accelerometer.cpp>

/**
* @example TestAccelerometer.c
*/

int main(int argc, char *argv[])
{
	int value=0;
	int valueMax=0;
	int valueMin=0;
	
	if(argc<2)
	{
		puts("\nUSE:\nTestAccelerometer <type>\n");
		puts("types:");
		puts("\tMac <dimension>");
		puts("\tMoko <dimension>\n");
		puts("\t  e.g.");
		puts("\t    TestAccelerometer Mac 0 => Shows the accelerometer value of the MacBook for X dimension.");
		puts("\t    TestAccelerometer Mac 1 => Shows the accelerometer value of the Neo for Y dimension.\n");

		exit(EXIT_SUCCESS);
	}
	
	if (strcmp(argv[1],"Mac") == 0)
	{
		CMAccelerometer accel("/dev/input/event10");
		while(1)
		{
			accel.check();
			value=accel.getValue(atoi(argv[2]));
			printf("\nValue:%d",value);
			// MAX and MIN
			if (valueMax < value)
				valueMax = value;
				
			if (valueMin > value)
				valueMin = value;
				
			printf("\t Max:%d   \tMin:%d\n",valueMax,valueMin);
			usleep(5000);
		}//END while
	}//END Mac
	
	if (strcmp(argv[1],"Moko") == 0)
	{
		CMAccelerometer accel("/dev/input/event3");
		while(1)
		{
			accel.check();
			value=accel.getValue(atoi(argv[2]));
			printf("\nValue:%d",value);
			
			// MAX and MIN
			if (valueMax < value)
			{	valueMax = value; }
				
			if (valueMin > value)
			{	valueMin = value; }
				
			printf("\t Max:%d   \tMin:%d\n",valueMax,valueMin);
			usleep(5000);
		}//END while
	}//END Moko
			
}//END main
